<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/5/10
 * Time: 8:39
 */

namespace app\adminapiv3\controller;


class HostExclude extends Base
{
    /**
     * @name 列表
     * @Author wx
     * @date 2019/8/15 14:42
     */
    public function list($hostId)
    {
        $params['content'] = $this->filterInput('content', 'get');
        $params['descirption'] = $this->filterInput('descirption', 'get');
        $params['type'] = $this->filterInput('type', 'get');
        $params['auto_defense'] = $this->filterInput('auto_defense', 'get');
        $params['illegal_modify'] = $this->filterInput('illegal_modify', 'get');
        $params['create'] = $this->filterInput('create', 'get');
        $params['modify'] = $this->filterInput('modify', 'get');
        $params['del'] = $this->filterInput('del', 'get');
        $params['status'] = $this->filterInput('status', 'get');

        $service = new \app\adminapiv3\service\HostExclude();
        $data = $service->list($hostId, $params, $this->getLimit());

        self::jsonOutPut($data);
    }

    /**
     * @name 删除
     * @Author wx
     * @date time
     */
    public function del($host_id)
    {
        global $logContent;
        $logContent = '删除排除策略';

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $id  = $this->filterInput('id*','post');

        $service = new \app\adminapiv3\service\HostExclude();
        $service->del($id);

        $this->jsonOutPut([], true);

        $this->Async('Defense', 'TpWhites');
        $this->Async('Defense', 'AdWhites');

    }

    /**
     * @name 添加
     * @Author wx
     * @date 2019/8/15 14:42
     */
    public function add($host_id)
    {
        global $logContent;
        $logContent = '添加排除策略';

        $insertData['host_id'] = $host_id;//主机id
        $insertData['status'] = $this->filterInput('status*','post');//状态
        $insertData['type'] = $this->filterInput('type','post', 1);//类型
        $insertData['auto_defense'] = $this->filterInput('auto_defense','post', 0);//主动防御
        $insertData['illegal_modify'] = $this->filterInput('illegal_modify','post', 0);//文件篡改
        $insertData['content'] = $this->filterInput('content','post', '');//内容
        $insertData['descirption'] = $this->filterInput('descirption','post', '');//描述
        $insertData['create'] = $this->filterInput('create','post',0);//创建
        $insertData['modify'] = $this->filterInput('modify','post', 0);//修改
        $insertData['del'] = $this->filterInput('del','post', 0);//删除

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $service = new \app\adminapiv3\service\HostExclude();
        $service->add($insertData);

        $this->jsonOutPut([], true);

        $this->Async('Defense', 'TpWhites');
        $this->Async('Defense', 'AdWhites');
    }

    /**
     * @name 添加
     * @Author wx
     * @date 2019/8/15 14:42
     */
    public function modify($host_id)
    {
        global $logContent;
        $logContent = '修改排除策略';

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $id = $this->filterInput('id*','post');//主机id
        $updateData['status'] = $this->filterInput('status*','post');//状态
        $updateData['type'] = $this->filterInput('type','post', 1);//类型
        $updateData['auto_defense'] = $this->filterInput('auto_defense','post', 0);//主动防御
        $updateData['illegal_modify'] = $this->filterInput('illegal_modify','post', 0);//文件篡改
        $updateData['content'] = $this->filterInput('content','post', '');//内容
        $updateData['descirption'] = $this->filterInput('descirption','post', '');//描述
        $updateData['create'] = $this->filterInput('create','post',0);//创建
        $updateData['modify'] = $this->filterInput('modify','post', 0);//修改
        $updateData['del'] = $this->filterInput('del','post', 0);//删除


        $service = new \app\adminapiv3\service\HostExclude();
        $service->modify($id, $updateData);

        $this->jsonOutPut([], true);

        $this->Async('Defense', 'TpWhites');
        $this->Async('Defense', 'AdWhites');
    }
}